package com.example.demo.controller;
import javax.annotation.Resource;
import com.zengtengpeng.common.utils.ExcelUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.zengtengpeng.common.bean.DataRes;
import java.util.List;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.stereotype.Controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.example.demo.bean.SysConfig;
import com.example.demo.service.SysConfigService;


/**
 *参数配置表 controller
 */
@Api(description="参数配置表")
@Controller
public class SysConfigController  {


	@Resource
	private SysConfigService sysConfigService;
	/**
	 * 删除-参数配置表
	 */
	@ResponseBody
	@RequestMapping("sysConfig/deleteByPrimaryKey")
	@ApiOperation(value="根据主键删除", notes="参数只用到了主键id,其他参数忽略" ,httpMethod="POST")
	public DataRes deleteByPrimaryKey(SysConfig sysConfig,HttpServletRequest request,HttpServletResponse response){
		return DataRes.success(sysConfigService.deleteByPrimaryKey(sysConfig));
	}


	/**
	 *  保存 (主键为空则增加否则修改)-> 参数配置表
	 */
	@ResponseBody
	@RequestMapping("sysConfig/save")
	@ApiOperation(value="保存", notes="主键为空则增加否则修改" ,httpMethod="POST")
	public DataRes save(SysConfig sysConfig,HttpServletRequest request,HttpServletResponse response){
		if(sysConfig.getConfigId()==null){
			return DataRes.success(sysConfigService.insert(sysConfig));
		}
		return DataRes.success(sysConfigService.update(sysConfig));

	}


	/**
	 * 根据主键查询->参数配置表
	 */
	@ResponseBody
	@RequestMapping("sysConfig/selectByPrimaryKey")
	@ApiOperation(value="根据主键查询", notes="参数只用到了主键." ,httpMethod="POST")
	public DataRes selectByPrimaryKey(SysConfig sysConfig,HttpServletRequest request,HttpServletResponse response){
		return DataRes.success(sysConfigService.selectByPrimaryKey(sysConfig));
	}


	/**
	 * 根据条件查询(所有的实体属性都是条件,如果为空则忽略该字段)->参数配置表
	 */
	@ResponseBody
	@RequestMapping("sysConfig/selectByCondition")
	@ApiOperation(value="根据条件查询", notes="参数为空则忽略." ,httpMethod="POST")
	public DataRes selectByCondition(SysConfig sysConfig,HttpServletRequest request,HttpServletResponse response){
		return DataRes.success(sysConfigService.selectByCondition(sysConfig));
	}


	/**
	 * 分页查询 (所有的实体属性都是条件,如果为空则忽略该字段) (详见Page类.所以的实体都继承该类 默认 page=1 pageSize=10)->参数配置表
	 */
	@ResponseBody
	@RequestMapping("sysConfig/selectAllByPaging")
	@ApiOperation(value="分页查询", notes="默认page=1pageSize等于10详见Page类(所有bean都继承该类).参数为空则忽略" ,httpMethod="POST")
	public DataRes selectAllByPaging(SysConfig sysConfig,HttpServletRequest request,HttpServletResponse response){
		return DataRes.success(sysConfigService.selectAllByPaging(sysConfig));
	}


	/**
	 * 导出报表->参数配置表
	 */
	@RequestMapping("sysConfig/export")
	@ApiOperation(value="导出excel", notes="导出全部数据.参数为空则忽略." ,httpMethod="POST")
	public void export(SysConfig sysConfig,HttpServletRequest request,HttpServletResponse response){
		List<SysConfig> list= sysConfigService.selectAll(sysConfig);
		Map<String, String> header = new LinkedHashMap<>();
		header.put("configId", "参数主键");
		header.put("configName", "参数名称");
		header.put("configKey", "参数键名");
		header.put("configValue", "参数键值");
		header.put("configType", "系统内置（Y是 N否）");
		header.put("createBy", "创建者");
		header.put("createTime_", "创建时间");
		header.put("updateBy", "更新者");
		header.put("updateTime_", "更新时间");
		header.put("remark", "备注");
		ExcelUtils.exportExcel("参数配置表",header,list,response,request);

	}


}
